package com.leyou.search.controller;

import com.leyou.common.vo.PageResult;
import com.leyou.search.dto.GoodsDTO;
import com.leyou.search.dto.SearchRequest;
import com.leyou.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author Eric
 * @version v1.0
 * @package com.leyou.search.controller
 * @date 2019/7/1 17:17
 * @description:
 **/
@RestController
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 分页查询商品信息
     * @param request
     * @return
     */
    @PostMapping("page")
    public ResponseEntity<PageResult<GoodsDTO>> queryGoodsBykey(@RequestBody SearchRequest request){
        return ResponseEntity.ok(searchService.queryGoodsBykey(request));
    }


    /**
     * 商品分类与品牌的聚合
     * @param request
     * @return
     */
    @PostMapping("filter")
    public ResponseEntity<Map<String, List<?>>> queryByFilter(@RequestBody SearchRequest request){
            return ResponseEntity.ok(searchService.queryByFilter(request));
    }

}
